<?php
/**
 * Created by PhpStorm.
 * User: qixiuxiu
 * Date: 2017/4/7
 * Time: 14:45
 */
namespace Simplex;

//引用事件订阅器
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
//class ContentLengthListener implements EventSubscriberInterface{
class ContentLengthListener {
    public function onResponse(ResponseEvent $event){
        $response = $event->getResponse();
        //设置响应的Content-Length
        $headers = $response->headers;

        if (!$headers->has('Content-Length') && !$headers->has('Transfer-Encoding')) {
            $headers->set('Content-Length', strlen($response->getContent()));
        }
        $response->setContent(strlen($response->getContent()).'ContentLengthListener监听2');
        $response->send();
    }
//    public static function getSubscribedEvents()
//    {
//        return array('response' => array('onResponse', -255));
//    }
}